﻿using System;

namespace ForgeCraft
{
    public class CmdAbout : Command
    {
        public override string name { get { return "about"; } }
        public override string shortcut { get { return "b"; } }
        public override string type { get { return "op"; } }
        public override bool consoleUsable { get { return false; } }
        public override Permission defaultRank { get { return Permission.Guest; } }
        public CmdAbout() { }

        public override void Use(Player p, string message)
        {
            //TODO: Put a handler in here or something
            p.Message("Click or place a block you want identified");
            p.waitingCoords = true;

            System.Timers.Timer waitTimer = new System.Timers.Timer(500);

            int i = 0;

            waitTimer.Elapsed += delegate
            {
                i++;

                if (p.queryBlockPos.y != 255)
                {
                    waitTimer.Stop();
                    p.waitingCoords = false;

                    ChunkBlock cb = p.currentWorld.GetBlock(p.queryBlockPos.x, p.queryBlockPos.y, p.queryBlockPos.z);

                    p.Message("Blockinfo for " + cb.type + " at " + p.queryBlockPos.x + " " + p.queryBlockPos.y + " " + p.queryBlockPos.z + ":");
                    p.Message("Metadata: " + cb.metadata + " Lighting: " + cb.lighting);

                    p.queryBlockPos.y = 255;
                    waitTimer.Dispose();
                }

                if (i == 8)
                {
                    p.Message("Check aborted!");
                    p.waitingCoords = false;

                    waitTimer.Stop();
                    waitTimer.Dispose();
                }

            };

            waitTimer.Start();

        }
        public override void Help(Player p)
        {
            p.Message(Color.Aqua + "/about " + Color.Help + "- Displays block info");
        }
    }
}